package com.shchuangzhi.smartguard.core;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by j_hu on 6/19/17.
 */

public class SyncRecord {
    private DBHelper dbHelper;
    private Map<String, String> meta = new HashMap<>();
    private static final SyncRecord record = new SyncRecord();

    public SyncRecord() {

    }

    public SyncRecord with(DBHelper dbHelper) {
        this.dbHelper = dbHelper;
        return this;
    }

    public boolean isEmpty() {
        return meta.size() == 0;
    }

    public void add(String name, String lastSyncTime) {
        meta.put(name, lastSyncTime);
    }

    public boolean update(String name, String lastSyncTime) {
        boolean updateOk = dbHelper.updateSyncRecord(name, lastSyncTime);
        if (updateOk) {
            meta.put(name, lastSyncTime);
        }
        return updateOk;
    }

    public void empty() {
        meta.clear();
    }

    public Map<String, String> asMap() {
        return meta;
    }

    public static SyncRecord getInstance() {
        return record;
    }
}
